package com.base.myproject.client.HR.Training;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BaseTreeStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.busi.BO.TreeNodeModelData;
import com.base.myproject.client.busi.business.BusinessRatify;
import com.base.myproject.client.jdbc.DataSet;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.system.Env;
import com.base.myproject.client.tools.CommandSyncGetModelDatas;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.base.myproject.client.ui.celleditor.BaseComboBoxX;
import com.base.myproject.client.ui.dialog.SelectItemDialog;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.TreePanelEvent;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.StoreFilterField;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.extjs.gxt.ui.client.widget.grid.HeaderGroupConfig;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanelSelectionModel;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel.CheckCascade;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel.CheckNodes;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class Training_Task extends BaseJDBCPanel{
	TabPanel tabPanel = null; 
	String tree_depcode=null;//讲当前树形结构中选中的部门id保存
	TreePanel<TreeNodeModelData> treePanel = null;
	// 创建树形结构的数据表
	BaseTreeStore<TreeNodeModelData> treeStore = null;
	BaseComboBoxX buser;//部门人员
	Button getlist = new Button("选择工作任务清单");
	StoreFilterField<BusiObject> ajaxfield;//类似ajax的自动查询框
	String results = null;
	String bcode = Env.getEnvbcode();
	
	public Training_Task(){
		String sql = "select substring('id like '''+replace(permissionsbcode,';','%'' or id like '''),9," +
		"len('id like '''+replace(permissionsbcode,';','%'' or id like '''))-21) as result from" +
		" busipermissions where bcode = '"+bcode+"' and busicode = 8010";
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService2.getDataSet(sql, new AsyncCallback<DataSet>(){
		@Override
			public void onFailure(Throwable caught) {	
			}
			@Override
			public void onSuccess(DataSet result) {  
			   results = result.getValue(0, "result");
			   init();
			}
		});
	}
	public void init(){
		initwidget();
	    registerMainStore(mainstore);
		registerStore(mainstore);
		registerStore(list_store);
	}
	public void complete()
	{
		super.complete();
	}
	private void initwidget() {
		HorizontalPanel hp=new HorizontalPanel();
		hp.add(getTreePanel());
		
		VerticalPanel   vp=new VerticalPanel();
		vp.setSpacing(1);
		FieldSet fs = new FieldSet();
		fs.setWidth(863);
		fs.setHeight(38);
		fs.setStyleName("fieldset_css2");
		fs.setHeading("查询操作");
		fs.add(cread_field());
		vp.add(fs);
		
		HorizontalPanel hp2=new HorizontalPanel();
		hp2.add(getmain_grid());
		
		VerticalPanel   vp2=new VerticalPanel();
		vp2.add(getBaseFormPanel());
		vp2.add(getlist);
		getlist.addListener(Events.Select, getListener());
		
		HorizontalPanel hp3=new HorizontalPanel();
		hp3.add(getgrid());
		hp3.add(getRecordgrid());
		vp2.add(hp3);
		
		hp2.add(vp2);

		vp.add(hp2);
		
		hp.add(vp);
		
		add(hp);
		 this.layout();
	}
	
	TreePanel<TreeNodeModelData> getTreePanel() {
		if (treePanel == null) {
			initTreePanel();
		}
		return treePanel;
	}
	BaseTreeStore<TreeNodeModelData> getTreeStore() {
		if (treeStore == null) {
			initTreeStore();
		}
		return treeStore;
	}
	BaseTreeStore<TreeNodeModelData> initTreeStore() {
		StoreInfo si = new StoreInfo();
		String sql2 = "select icode,id,name from SystemInfo where id like "+results+" order by id asc";
		si.setSql(sql2);
		si.setTreesortcolumn("id");
		si.setKeyname(new String[] { "icode" });
		si.setTablename("SystemInfo");
		treeStore = new BaseTreeStore<TreeNodeModelData>(si, false);
		treeStore.load();
		return treeStore;
		
	}
	// 实例化TreePanel
	TreePanelSelectionModel<TreeNodeModelData> tpsm = new TreePanelSelectionModel<TreeNodeModelData>();
	void initTreePanel() {
		//super.onRender();  
		treePanel = new TreePanel<TreeNodeModelData>(getTreeStore());
		treePanel.setWidth(150);
		treePanel.setBorders(true);
		treePanel.setHeight(450);
		treePanel.setDisplayProperty("name");
		treePanel.setSelectionModel(tpsm);
		treePanel.setCheckStyle(CheckCascade.PARENTS); 
		treePanel.setCheckNodes(CheckNodes.BOTH);  
		treePanel.setCheckable(false);
		treePanel.setAutoLoad(true);
		treePanel.addListener(Events.OnClick, new Listener<TreePanelEvent<TreeNodeModelData>>() {   
			public void handleEvent(TreePanelEvent<TreeNodeModelData> be) {   
				final String id=be.getItem().get("id").toString();//部门id
				tree_depcode=id;
				if(!id.equals("00")){//表示为主节点 不因有任何操作
					 String sql="select  * from systeminfo where len('"+id+"')=(select len(max(id)) from  systeminfo)";
					final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
					   greetingService2.getDataSet(sql, new AsyncCallback<DataSet>(){
						@Override
						public void onFailure(Throwable caught) {	
						}
						@Override
						 public void onSuccess(DataSet result) {  
			   			   if(result.getRowCount()>0){
			   				  set_grid(id);
			   				  buser.setFilter(" WHERE systemid like '"+tree_depcode+"%25' ");
			   			   }
			   					   
						  }
					     });	   
				 }
				
	  		} 
		    });   
	}
	void set_grid(String id){
		String sql=" select * from hr_InitialJobTraining where sectionCode ='"+id+"'";
		maingrid.getBg().getStore().getStoreinfo().setSql(sql);
		maingrid.getBg().getStore().reload();
		maingrid.getBg().getView().refresh(true);
	
	}
	/*****/
	BaseStore<BusiObject> mainstore = null;
	BaseStore<BusiObject> getmainStore(){
	if(mainstore==null) 
	{
		createmainStore();
	}
	return mainstore;}
	ModelType typef;
	BaseStore<BusiObject> createmainStore(){
		typef = new ModelType();
		typef.setRoot("records");
		typef.setRecordName("record");
		typef.setTotalName("totle");
		typef.addField("icode");
		typef.getField("icode").setType(Long.class);
		typef.addField("departmentCode");
		typef.getField("departmentCode").setType(String.class);
		typef.addField("sectionCode");
		typef.getField("sectionCode").setType(String.class);
		typef.addField("bcode");
		typef.getField("bcode").setType(String.class);
		typef.addField("joinDate");
		typef.getField("joinDate").setType(Date.class);
		typef.addField("position");
		typef.getField("position").setType(String.class);
		typef.addField("sectionTrainingChampion");
		typef.getField("sectionTrainingChampion").setType(String.class);
		typef.addField("attendanced");
		typef.getField("attendanced").setType(Boolean.class);
		typef.addField("grade");
		typef.getField("grade").setType(String.class);
	StoreInfo info = new StoreInfo();
	info.setTablename("hr_InitialJobTraining");
	info.setKeyname(new String[] { "icode"});
	info.setSql("select * from hr_InitialJobTraining");
	mainstore = new BaseStore<BusiObject>(typef, info);
	 return mainstore;}
	BaseGridPanel maingrid=null;
	BaseGridPanel getmain_grid(){
		if(maingrid==null){
			createminGrid();
		}
		return maingrid;
	}
	void createminGrid(){
	CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
	List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
	columns.add(cbs.getColumn());


	//ColumnConfig C2 = new ColumnConfig("departmentCode", "departmentCode", 80);
	//columns.add(C2);
	//----
	GridCellRenderer<ModelData>	renderer = new GridCellRenderer<ModelData>() {              
	      public String render(ModelData model, String property, ColumnData d, int rowIndex,
	          int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {             
	    	  //GWT.log("class="+model);
	    	  //GWT.log("class="+model.get(property));
	    	  if(model.get(property) !=null && model.get(property) instanceof ModelData)
	    	  {
	    		  return ((ModelData)model.get(property)).get("value");
	    	  }                                                                            
	    	  return model.get(property);                                                     
	      }                                                                                 
	    };  
	//----
	ColumnConfig C3 = new ColumnConfig("sectionCode", "分部门", 80);
	BaseComboBoxForm<BaseModelData> bsb2 = new BaseComboBoxForm<BaseModelData>("bcode","bname","bcode","",true);
	bsb2.setReadOnly(true);
	C3.setRenderer(bsb2);
	C3.setEditor(bsb2.getCelEditor());
	columns.add(C3);
	ColumnConfig C4 = new ColumnConfig("bcode", "姓名", 60);
	C4.setRenderer(renderer);
	columns.add(C4);

	ColumnModel cm = new ColumnModel(columns);
	maingrid = new BaseGridPanel(getmainStore(), cm,true,true);
	cbs.setSelectionMode(SelectionMode.SINGLE);
	maingrid.getBg().setSelectionModel(cbs);
	maingrid.getBg().setWidth(170);
	maingrid.getBg().setHeight(378);
	}
	BaseFormPanel form = null;
	 BaseFormPanel getBaseFormPanel() {
			if (form == null) {
				createForm();
			}
			return form;
		 }
	 BaseComboBoxForm<BaseModelData> up_dep;//分部门
	 BaseComboBoxForm<BaseModelData> dep ;//部门  
	// TextField<String> up_dep;
	// TextField<String> dep;
	 DateField C_data5 ;//入职日期
	 TextField<String> C_num6;//职务
	 void createForm() {
			form = new BaseFormPanel(getmainStore(),false);
			TableLayout tl = new TableLayout(6);
			TableData td = new TableData();
			td.setRowspan(1);
			td.setHorizontalAlign(HorizontalAlignment.LEFT);
			td.setVerticalAlign(VerticalAlignment.TOP);
			td.setPadding(2);
			form.setPadding(3);
			form.setLayout(tl);
			form.setHeaderVisible(false);

			form.add(new Label("姓名:"),td);
			buser = new BaseComboBoxX("bname","bcode", "bcode",	" WHERE systemid like '%25"+tree_depcode+"%25'");
			
			buser.addListener(Events.Change, getListener());
			buser.setWidth(127);
			buser.setName("bcode");
			form.add(buser,td);		
			
			form.add(new Label("部门:"),td);
			up_dep  = new BaseComboBoxForm<BaseModelData>("id","name","SystemInfo","",true); 
			up_dep.setWidth(127);
			up_dep.setReadOnly(true);
			up_dep.setFireChangeEventOnSetValue(true);
			up_dep.setName("departmentCode");
			form.add(up_dep,td);
			
			form.add(new Label("分部门:"),td);
			dep= new BaseComboBoxForm<BaseModelData>("id","name","SystemInfo","",true); 
			dep.setWidth(127);
			dep.setReadOnly(true);
			dep.setFireChangeEventOnSetValue(true);
			dep.setName("sectionCode");
			form.add(dep,td);
			
			form.add(new Label("入职日期:"),td);
			  C_data5  = new DateField(); 
			  C_data5.setFireChangeEventOnSetValue(true);
			 C_data5.setWidth(127);
			C_data5.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd")); 
			C_data5.setName("joinDate");
			form.add(C_data5,td);
			
			form.add(new Label("职务:"),td);
			C_num6  = new TextField<String>(); 
			C_num6.setFireChangeEventOnSetValue(true);
			C_num6.setName("position");
			form.add(C_num6,td);
			
			form.add(new Label("分部培训负责人:"),td);
			TextField<String> C_num7  = new TextField<String>(); 
			C_num7.setName("sectionTrainingChampion");
			form.add(C_num7,td);
			form.add(new Label("是否参加:"),td);
			 CheckBox C_num8  = new CheckBox(); 
			C_num8.setName("attendanced");
			form.add(C_num8,td);
			form.add(new Label("评定:"),td);
			TextField<String> C_num9  = new TextField<String>(); 
			C_num9.setName("grade");
			form.add(C_num9,td);
			form.setWidth(694);
			form.setHeight(84);
			 form.inited(); 
	};
	/***********hr_InitialJobTraining_list*************/
	BaseStore<BusiObject> list_store = null;
	BaseStore<BusiObject> getlist_store(){
	if(list_store==null) 
	{
		createlist_store();
	}
	return list_store;}
	BaseStore<BusiObject> createlist_store(){
	ModelType type = new ModelType();
	type.setRoot("records");
	type.setRecordName("record"); 
	type.setTotalName("totle");
	type.addField("icode");
	type.getField("icode").setType(Long.class);
	type.addField("micode");
	type.getField("micode").setType(Long.class);
	type.addField("InitialJobTaskList_icode");
	type.getField("InitialJobTaskList_icode").setType(Long.class);
	type.addField("tasksList");
	type.getField("tasksList").setType(String.class);
	type.addField("TrainingDate");
	type.getField("TrainingDate").setType(Date.class);
	type.addField("trainer");
	type.getField("trainer").setType(String.class);
	type.addField("evaluation");
	type.getField("evaluation").setType(String.class);
	StoreInfo info = new StoreInfo();
	info.setTablename("hr_InitialJobTraining_list");
	info.setKeyname(new String[] { "icode"});
	info.setSql("select * from hr_InitialJobTraining_list where micode='{icode}'");
	info.setParent(mainstore);// 关联主表
	info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
	info.setLinkparent_chile_columns(new String[] { "micode" });// 关联主表字段
	list_store = new BaseStore<BusiObject>(type, info);
	 return list_store;}
	
	BaseGridPanel grid=null;
	BaseGridPanel getgrid(){
		if(grid==null){
			createGrid();
		}
		return grid;
	}
	void createGrid(){
	
	List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
	CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
	columns.add(cbs.getColumn());

	ColumnConfig C4 = new ColumnConfig("tasksList", "工作任务清单", 150);
	TextField C_num4  = new TextField<String>(); 
	C_num6.setFireChangeEventOnSetValue(true);
	C_num6.setName("tasksList");
	C4.setEditor(new CellEditor(C_num4));
	columns.add(C4);
	
	ColumnConfig C5 = new ColumnConfig("TrainingDate", "培训日期", 120);
	DateField C_data5  = new DateField(); 
	 C_data5.setWidth(127);
	C_data5.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd")); 
	C_data5.setName("TrainingDate");
	C5.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
	C5.setEditor(new CellEditor(C_data5));
	columns.add(C5);
	
	ColumnConfig C6 = new ColumnConfig("trainer", "培训师", 80);
	TextField C_num6= new TextField<String>(); 
	C_num6.setFireChangeEventOnSetValue(true);
	C_num6.setName("trainer");
	C6.setEditor(new CellEditor(C_num6));
	columns.add(C6);
	
	
	ColumnConfig C8 = new ColumnConfig("evaluation", "评估", 40);
	TextField C_num8= new TextField<String>(); 
	C_num8.setFireChangeEventOnSetValue(true);
	C_num8.setName("evaluation");
	C8.setEditor(new CellEditor(C_num8));
	columns.add(C8);

		
	ColumnModel cm = new ColumnModel(columns);
	grid = new BaseGridPanel(getlist_store(), cm);
	cbs.setSelectionMode(SelectionMode.SINGLE);
	grid.getBg().setSelectionModel(cbs);
	grid.getBg().setHeight(269);
	grid.getBg().setWidth(418);
	}
	/************hr_RetrainingRecord*****************/
	BaseStore<BusiObject> Recordstore = null;
	BaseStore<BusiObject> getRecordStore(){
	if(Recordstore==null) 
	{
		createRecordStore();
	}
	return Recordstore;}
	BaseStore<BusiObject> createRecordStore(){
	ModelType type = new ModelType();
	type.setRoot("records");
	type.setRecordName("record");
	type.setTotalName("totle");
	type.addField("icode");
	type.getField("icode").setType(Long.class);
	type.addField("InitialJobTraining_icode");
	type.getField("InitialJobTraining_icode").setType(Long.class);
	type.addField("trainingDate");
	type.getField("trainingDate").setType(Date.class);
	type.addField("trainer");
	type.getField("trainer").setType(String.class);
	type.addField("evaluation");
	type.getField("evaluation").setType(String.class);
	StoreInfo info = new StoreInfo();
	info.setTablename("hr_RetrainingRecord");
	info.setKeyname(new String[] { "icode"});
	info.setSql("select * from hr_RetrainingRecord where InitialJobTraining_icode='{icode}'");
	info.setParent(getlist_store());// 关联主表
	info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
	info.setLinkparent_chile_columns(new String[] { "InitialJobTraining_icode" });// 关联子表字段
	Recordstore = new BaseStore<BusiObject>(type, info);
	 return Recordstore;}
	
	BaseGridPanel Recordgrid=null;
	BaseGridPanel getRecordgrid(){
		if(Recordgrid==null){
			creatRecordeGrid();
		}	
		return Recordgrid;
	}
	
	void creatRecordeGrid(){
	CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
	List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
	columns.add(cbs.getColumn());

	ColumnConfig C3 = new ColumnConfig("trainingDate", "培训日期", 80);
	DateField C_data3  = new DateField(); 
	C_data3.setWidth(127);
	C_data3.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd")); 
	C_data3.setName("trainingDate");
	C3.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
	C3.setEditor(new CellEditor(C_data3));
	columns.add(C3);
	
	ColumnConfig C4 = new ColumnConfig("trainer", "培训师", 80);
	TextField C_num4= new TextField<String>(); 
	C_num4.setFireChangeEventOnSetValue(true);
	C_num4.setName("trainer");
	C4.setEditor(new CellEditor(C_num4));
	columns.add(C4);
	
	ColumnConfig C5 = new ColumnConfig("evaluation", "评估", 80);
	TextField C_num5= new TextField<String>(); 
	C_num5.setFireChangeEventOnSetValue(true);
	C_num5.setName("evaluation");
	C5.setEditor(new CellEditor(C_num5));
	columns.add(C5);

	ColumnModel cm = new ColumnModel(columns);
	Recordgrid = new BaseGridPanel(getRecordStore(), cm,true,true);
	cbs.setSelectionMode(SelectionMode.SINGLE);
	Recordgrid.getBg().setSelectionModel(cbs);
	Recordgrid.getBg().setHeight(269);
	Recordgrid.getBg().setWidth(270);
	}
	/*******************************/
	int sync = 0;                                                      
	Listener<BaseEvent> defaultlistener;                                                                                                
	Listener<BaseEvent> getListener() {                                
		if(defaultlistener!=null)                                        
		{                                                                
			return defaultlistener;                                        
		}                                                                                                                           
		defaultlistener = new Listener<BaseEvent>() {                    
			public void handleEvent(BaseEvent be) {                        
				sync++;                                                    
				try {                                                      
					if (sync == 1) {                                   
						if (be.getType() == Events.Select) {  
							if(be.getSource().equals(getlist)){
								//MessageBox.alert("警告", mainstore.getValue("icode").toString(),	null); 
								addrecord();
							}
						}else if(be.getType() == Events.OnClick){
						} else if (be.getType() == Events.Change){
							if(be.getSource().equals(buser)){
								String bname=buser.getValue().get("value");
								//GWT.log("aa"+buser.getValue().get("value"));
								//GWT.log("bb"+buser.getValue().get("code"));
								 String sql="select up_department,systemid,entrydate," +
								 		"employoutertitle from " +
								 		"bcode left join  bcode_job on bcode.bcode=bcode_job.bcode where " +
								 		" bname='"+bname+"'";
									final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
									   greetingService2.getDataSet(sql, new AsyncCallback<DataSet>(){
										@Override
										public void onFailure(Throwable caught) {	
										}
										@Override
										 public void onSuccess(DataSet result) { 
											/**TextField<String> up_dep;
											 TextField<String> dep;
											 DateField C_data5 ;//入职日期
											 TextField<String> C_num6;//职务**/
											if(result.getRowCount()>0){
												//up_dep.setValue(result.getValue(0, "up_department"));
												//dep.setValue(result.getValue(0, "systemid"));
												up_dep.setSimpleValue(result.getValue(0, "up_department"));
												dep.setSimpleValue(result.getValue(0, "systemid"));
												C_data5.setValue(change_to_date(result.getValue(0, "entrydate")));
												C_num6.setValue(result.getValue(0, "employoutertitle"));
											}
											 
										 }
									 });
							}
						}else if (be.getType() == Events.KeyUp) { 
							if (be instanceof ComponentEvent) {                    
								if (((ComponentEvent)be).getKeyCode() == 13) // 回车
								{                          
								}                          
							}                                  
						}                                          
					}                                                  
				} finally {                                                
					sync--;                                            
				}                                                          
			}                                                                                                                       
		};                                                               
		return defaultlistener;                                          
	}     
	void addrecord()
	{
		 SelectItemDialog s= new SelectItemDialog()
		 {
				@SuppressWarnings("unchecked")
				protected void onOK()
				{
					 super.onOK();
					 //注意grid是SelectItemDialog里的grid
					for(BusiObject bo: grid.getSelectionModel().getSelectedItems())
					{
						HashMap hm = new HashMap();
						hm.put("micode", mainstore.getValue("icode").toString());///主表icode
						hm.put("InitialJobTaskList_icode", bo.get("icode"));//工作任务清单icode
						hm.put("tasksList", bo.get("taskName"));//工作任务清单
						//hm.put("TrainingDate", "");//培训日期
						hm.put("trainer", "");//培训人
						hm.put("evaluation", "");//评估
						getlist_store().add(hm);
					}
				}
		 };
		 s.setSelectmode(2);
		 s.setColumndisplayname(new String[]{"编号","任务编号","任务名称"});
		 s.setColumnname(new String[]{"icode","taskNo","taskName"});
		 CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
		 csgmd2.setSqlname("InitialJobTaskList");
		 s.setCsgmd2(csgmd2);
		 s.show();
	}
	
	Date change_to_date(String strdate){//2010-09-15
		java.util.Date currentTime = new java.util.Date();
		Date df_date=new Date();
		int year=Integer.parseInt(strdate.substring(0, 4));
		int month=Integer.parseInt(strdate.substring(5, 7));
		int day=Integer.parseInt(strdate.substring(8, 10));
		df_date.setYear(year-1900);
		df_date.setMonth(month-1);
		df_date.setDate(day);
		return df_date;
	}	
	/**
	 * 过滤
	 * @param store
	 * @param parent
	 * @param record
	 * @param property
	 * @param filter
	 * @return  ajax 查询
	 */
	protected boolean Select(Store<BusiObject> store,
			BusiObject parent, BusiObject record, String property,
			String filter) {
		for (int i = 0; i < typef.getFieldCount(); i++) {
			Object name = record.get(typef.getField(i).getName());	
			//TODO
			if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
				return true;
			}
		}
		return false;
	}	
	StoreFilterField cread_field(){
		ajaxfield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {

			return	Select(store,parent,record,property,filter);
			}

			@Override
			protected void onFilter() {
				super.onFilter();

				// grid.getSelectionModel().select(0);
			}

		};
		ajaxfield.setAutoWidth(true);
		ajaxfield.setToolTip("快速查找");
		ajaxfield.bind(getmainStore());
		this.ajaxfield=ajaxfield;
		return ajaxfield;
	}
	/************************************/

}
